﻿<cfsilent>
	<cfsetting requesttimeout="90" />
	<cfscript>
		
		sessionAdvice = getProperty("serviceFactory").getBean("sessionAdvice");
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		chooseProp = getProperty("serviceFactory").getBean("choosePropertyAdvice");
		taskProp = getProperty("serviceFactory").getBean("taskPropertyAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");

		termId = event.getArg("TermID");

		/* 学籍相关信息 */
		studentId = sessionAdvice.getAutherUserID();
		
		/* 读取学生的已选课程 */
		sql = "	SELECT
					c.cid,c.course_name,c.course_credit,
					tct.turn,
					tsc.task_type,tsc.scc_id,tsc.st,tsc.retaking,
					tsc.choose_time,tsc.choose_prop,tsc.task_id,tcp.prop_name
				FROM
					t_student_course tsc
					INNER JOIN t_course c ON tsc.cid = c.cid
					INNER JOIN t_course_prop tcp ON tcp.prop_id = tsc.prop_id
					INNER JOIN t_choose_turn tct ON tct.ct = tsc.ct
					INNER JOIN t_term tt ON tsc.term_id = tt.term_id
				WHERE
					tsc.stu_id = :studentId 
					AND
					tsc.term_id = :termId 
				ORDER BY
					tsc.st,tcp.prop_name,c.course_name";
		
		queryObj = new Query(datasource = application.dnsSlave);
		
		queryObj.addParam(name="studentId", value=studentId, cfsqltype="cf_sql_varchar");
		queryObj.addParam(name="termId", value=termId, cfsqltype="cf_sql_char");
		
		rs_choosen = queryObj.execute(sql=sql).getResult();
		
	</cfscript>
</cfsilent>

<cfif rs_choosen.recordCount GT 0>
	<table class="UIEditable">
		<thead>
			<tr>
				<td width="18"></td>
				<td>教学班</td>
				<td>任课教师</td>
				<td>学分</td>
				<!---<td>开课类别</td>--->
				<td>修读方式</td>
				<td>课程性质</td>
				<td>重修</td>
				<td>选课轮次</td>
				<td>选课时间</td>
			</tr>
		</thead>
		<tbody>
			<cfset row = 0 />
            <cfloop query="rs_choosen">
				<cfset row++ />
			
				<!--- 读取教学任务教师和任务性质 --->
				<cfswitch expression="#rs_choosen.task_type#">
					<cfcase value="P">
                        <cfset sql = "	SELECT
											tch.tch_name,tc.campus_name,tsk.task_week,
											CASE WHEN tsk.task_time IS NULL THEN '-' ELSE tsk.task_time END task_time,
											CASE WHEN tsk.task_place IS NULL THEN '-' ELSE tsk.task_place END task_place,
											tsk.task_prop,tsk.cidx
										FROM
											t_task tsk
											INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
											INNER JOIN t_campus tc ON tsk.campus_id = tc.campus_id
										WHERE
											tsk.tsk_id = :taskId " />
						<cfset queryObj = new Query(datasource=application.dnsSlave)/>
                        <cfset queryObj.addParam(name="taskId", value=rs_choosen.task_id, cfsqltype="cf_sql_varchar")/>
                        <cfset rs_task = queryObj.execute(sql=sql).getResult()/>
						
					</cfcase>
					<cfcase value="C">
                        <cfset sql = "	SELECT
											tch.tch_name,tc.campus_name,tsk.task_week,
											CASE WHEN tsk.task_time IS NULL THEN '-' ELSE tsk.task_time END task_time,
											CASE WHEN tsk.task_place IS NULL THEN '-' ELSE tsk.task_place END task_place,
											tsk.task_prop,tsk.cidx
										FROM
											t_common_task tsk
											INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
											INNER JOIN t_campus tc ON tsk.campus_id = tc.campus_id
										WHERE
											tsk.tsk_id = :taskId " />
						<cfset queryObj = new Query(datasource=application.dnsSlave)/>
                        <cfset queryObj.addParam(name="taskId", value=rs_choosen.task_id, cfsqltype="cf_sql_varchar")/>
                        <cfset rs_task = queryObj.execute(sql=sql).getResult()/>
					</cfcase>
					<cfcase value="R">
                        <cfset sql = "	SELECT
											tch.tch_name,tc.campus_name,tsk.task_week,
											CASE WHEN tsk.task_time IS NULL THEN '-' ELSE tsk.task_time END task_time,
											CASE WHEN tsk.task_place IS NULL THEN '-' ELSE tsk.task_place END task_place,
											tsk.task_prop,tsk.cidx
										FROM
											t_reopen_task tsk
											INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
											INNER JOIN t_campus tc ON tsk.campus_id = tc.campus_id
										WHERE
											tsk.tsk_id = :taskId " />
						<cfset queryObj = new Query(datasource=application.dnsSlave)/>
                        <cfset queryObj.addParam(name="taskId", value=rs_choosen.task_id, cfsqltype="cf_sql_varchar")/>
                        <cfset rs_task = queryObj.execute(sql=sql).getResult()/>
					</cfcase>
					<cfcase value="T">
                        <cfset sql = "	SELECT
											tch.tch_name,tc.campus_name,tsk.task_week,
											CASE WHEN tsk.task_time IS NULL THEN '-' ELSE tsk.task_time END task_time,
											CASE WHEN tsk.task_place IS NULL THEN '-' ELSE tsk.task_place END task_place,
											tsk.task_prop,tsk.cidx
										FROM
											t_sport_task tsk
											INNER JOIN t_teacher tch ON tch.tch_id = tsk.tch_id
											INNER JOIN t_campus tc ON tsk.campus_id = tc.campus_id
										WHERE
											tsk.tsk_id = :taskId " />
						<cfset queryObj = new Query(datasource=application.dnsSlave)/>
                        <cfset queryObj.addParam(name="taskId", value=rs_choosen.task_id, cfsqltype="cf_sql_varchar")/>
                        <cfset rs_task = queryObj.execute(sql=sql).getResult()/>
					</cfcase>
				</cfswitch>
                <cfif rs_task.recordCount GT 0>
					<!--- 如果教学任务有效 --->
					<cfset taskProp.parseProperty( rs_task.task_prop ) />
					<cfset chooseProp.parseProperty( rs_choosen.choose_prop ) />
					<tr class="editRows <cfif rs_choosen.st eq "R">noticeRow1</cfif> <cfif rs_choosen.st eq "F">noticeRow2</cfif>">
						<td><span class="index"><cfoutput>#row#</cfoutput></span></td>
						<td><cfoutput>#rs_choosen.course_name#</cfoutput>.-.<span class="numeric"><cfoutput>#rs_task.cidx#</cfoutput></span></td>
						<td><cfoutput>#rs_task.tch_name#</cfoutput></td>
						<td><span class="numeric"><cfoutput>#numberFormat(rs_choosen.course_credit, '_.__')#</cfoutput></span></td>
						<!---<td><cfoutput>#dictAdvice.getTaskType( rs_choosen.task_type )#</cfoutput></td>--->
						<td><cfoutput>#dictAdvice.getStudyType( rs_choosen.st )#</cfoutput></td>
						<td><cfoutput>#rs_choosen.prop_name#</cfoutput></td>
						<td><cfif rs_choosen.retaking eq "1">是</cfif></td>
						<td><cfoutput>#rs_choosen.turn#</cfoutput></td>
						<td><span class="numeric"><cfoutput>#datetimeAdvice.formatDatetimeString(rs_choosen.choose_time, 'YYYY-MM-DD HH:MI')#</cfoutput></span></td>
					</tr>
					<cfelse>
					<!--- 如果教学任务无效 则直接删除错误的选课记录 --->
				</cfif>
			</cfloop>
		</tbody>
	</table>
</cfif>
